<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h1>我的第一段 JavaScript</h1>

<p>在这里，JavaScript 更改了图像的 src 属性。</p>

<script>
  function light(sw){
    var pic;
    if (sw == 0){
      pic = "img/eg_bulboff.gif"
    }else {
      pic = "img/eg_bulbon.gif"
    }
    document.getElementById('myImage').src = pic;
  }
</script>

<img id="myImage" src="img/eg_bulboff.gif" width="109" height="180">

<p>
  <button type="button" onclick="light(1)">开灯</button>
  <button type="button" onclick="light(0)">关灯</button>
</p>

</body>
</html>